package com.sihai.ehr.web.action.ajax;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.Duty;
import com.sihai.ehr.model.biz.Grade;
import com.sihai.ehr.service.GradeService;
import com.sihai.ehr.web.action.EHRAction;

/**
 * 职等职级AJAX处理类
 * 
 * @author Henry-PC
 * 
 */
public class GradeJsonControl extends EHRAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8989499030788384727L;

	@BeanInject
	private GradeService gradeService;

	/** the return grade list */
	List<Grade> grades;

	/** the return grade level list */
	List<Grade> gradeLvs;

	/** duty id */
	private Long dutyId;

	/** grade name */
	private String gradeName;

	/**
	 * 根据职务编号获取职等列表
	 * 
	 * @return
	 */
	@Action(value = "/ajax/grade_list", results = { @Result(name = "success", type = "json", params = {
			"root", "grades" }) })
	public String getGradesByDutyId() {
		try {
			grades = gradeService.search(dutyId, "gradeName", null, null);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return SUCCESS;
	}

	@Action(value = "/ajax/grade_lvlist", results = { @Result(name = "success", type = "json", params = {
			"root", "gradeLvs" }) })
	public String queryGradesByGradeName() {
        if(gradeName == null || gradeName.isEmpty()){
            return SUCCESS; //直接返回
        }
		try {
			gradeLvs = gradeService.searchByGradeName(dutyId, gradeName, null,
					null);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return SUCCESS;
	}

	public List<Grade> getGrades() {
		return grades;
	}

	public void setGrades(List<Grade> grades) {
		this.grades = grades;
	}

	public List<Grade> getGradeLvs() {
		return gradeLvs;
	}

	public void setGradeLvs(List<Grade> gradeLvs) {
		this.gradeLvs = gradeLvs;
	}

	public Long getDutyId() {
		return dutyId;
	}

	public void setDutyId(Long dutyId) {
		this.dutyId = dutyId;
	}

	public String getGradeName() {
		return gradeName;
	}

	public void setGradeName(String gradeName) {
		this.gradeName = gradeName;
	}

}
